package com.hs.controller;

import com.github.pagehelper.PageInfo;
import com.hs.entity.ClassQaQuestion;
import com.hs.service.ClassQaQuestionService;
import com.hs.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;

@RestController
@RequestMapping("classqaquestion")
public class ClassQaQuestionController {
    @Autowired
    private ClassQaQuestionService classQaQuestionService;
    @PostMapping("add")
    public R addclassqaquestion(@RequestBody ClassQaQuestion classQaQuestion) {
        int i = classQaQuestionService.addClassQaQuestion(classQaQuestion);
        if (i > 0) {
            return R.ok("操作成功");
        }else{
            return R.fail("操作失败");
        }
    }
    @PutMapping("update")
    public R updateclassqaquestion(@RequestBody ClassQaQuestion classQaQuestion) {
        int i = classQaQuestionService.updateClassQaQuestion(classQaQuestion);
        if (i > 0) {
            return R.ok("操作成功");
        }else{
            return R.fail("操作失败");
        }
    }
    @DeleteMapping("{id}")
    public R deleteclassqaquestion(@PathVariable("id") Integer id) {
        int i = classQaQuestionService.deleteById(id);
        if (i > 0) {
            return R.ok("操作成功");
        }else{
            return R.fail("操作失败");
        }
    }
    @GetMapping("{id}")
    public R getclassqaquestionByid(@PathVariable("id") Integer id) {
        ClassQaQuestion classQaQuestion = classQaQuestionService.getClassQaQuestionById(id);
        return R.ok(classQaQuestion);
    }
    @GetMapping("page")
    public R getclassqaquestionpage(
                                    @RequestParam(defaultValue = "1",required = false) int pageNum,
                                    @RequestParam(defaultValue = "2",required = false) int pageSize) {
        PageInfo<ClassQaQuestion> cc = classQaQuestionService.getClassQaQuestionPage(pageNum, pageSize);
        return R.ok(cc);
    }
}
